/**
 *
 *  @auth xlx_good@qq.com
 *  @date 17/5/10.
 *
 */
import config from '../../config'
import axios from 'axios';

const defaults = {
  baseURL: ApiURL,
  timeout: 60000,
  headers: {'X-Requested-With': 'XMLHttpRequest'}
}

Object.assign(axios.defaults, defaults);

//请求拦截器
axios.interceptors.request.use(function(config){
  // 发送请求之前处理数据
  config.data = config.data ? config.data : {};
  return config;
}, function (error) {
  //请求错误进行处理f
  return Promise.reject(error);
})

//响应拦截器
axios.interceptors.response.use(function(response){
  //对响应数据进行处理
  if(response.data.returnCode == '100003'){
    // Store.commit('modifyLoginStatus', false);
    Cookie.remove('name');
    if(!pathReg.test(vm.$route.name) && vm.$route.name != '/'){
      MessageBox.alert(response.data.errorMsg).then(action => {
        location.href = '/#/login';
      });
    }
  }
  if(response.data.returnCode != '000000'){
    response.data.errorMsg !='' &&Toast(response.data.errorMsg);
  }
  return response.data;
}, function(error){
  //响应错误进行处理
  return Promise.reject(error);
})


//登录
export const login = (data) =>{
  // var params = new URLSearchParams();
  // params.append('param1', 'value1');
  // params.append('param2', 'value2');
  return axios.post('/buyerUser/login',data);
}
//登录是否显示验证码
export const showCode=(data)=>{
  return axios.post('/buyerUser/IsVerificationCode',data);
}
//注册
export const register = (data) =>{
  return axios.post('/buyer/register',data);
}
//获取站点列表
export const getSiteList =() =>{
  return axios.post('/sysSite/getSiteList');
}
//上传图片
export const imageUpload = (data) =>{
  return axios.post('/buyerUser/imageUpload', data, { headers: {'Content-Type': 'multipart/form-data'}});
}
//删除图片
export const imageDelete = (data) =>{
  return axios.post('/buyerUser/imageDelete', data);
}
//完善资料
export const complete = (data) =>{
  return axios.post('/buyer/editInfo', data);
}
//忘记密码
export const forgetPwd =(data) =>{
  return axios.post('/buyerUser/forgotPassword', data);
}
//重置密码
export const rePwd = (data) =>{
  return axios.post('/buyerUser/resetPassword', data);
}
//获取验证码
export const getVcode = ()=>{
  return ApiURL +  '/buyer/getVcode?' + parseInt(Math.random()*1e7);
}
//取消收藏
export const cancelFavorites = (data) => {
  return axios.post('/wareFavorites/cancelFavorites', data);
}
//我的收藏
export const getFavorites = (data) =>{
  return axios.post('/wareFavorites/myFavorites', data);
}
//查询收藏状态
export const getFavoritesStatus = (data) =>{
  return axios.post('/wareFavorites/getWareFavoritesStatus', data);
}
//我的业务员接口
export const getSalesman = (data) =>{
  return axios.post('/buyerUser/findSaleMan', data);
}
//我的上级
export const leader = () =>{
  return axios.get('/buyerUser/mySuperior');
}
//我的下级
export const subordinate = () =>{
  return axios.get('/buyerUser/mySubordinate');
}
//收货地址列表
export const getAddressList = () =>{
  return axios.get('/buyerAddress/buyerAddressList');
}
//获取收货地址详情
export const getAddress = (data) =>{
  return axios.post('/buyerAddress/getBuyerAddress',data);
}
//新增收货地址
export const addAddress = (data) =>{
  return axios.post('/buyerAddress/buyerAddressModify',data);
}
//编辑收货地址
export const updateAddress = (data) =>{
  return axios.post('/buyerAddress/buyerAddressModify',data);
}
//删除收货地址
export const delAddress = (data) =>{
  return axios.post('/buyerAddress/delBuyerAddress',data);
}
//获取省份
export const getCity = (data) =>{
  return axios.get('/sysRegion/getAddressData',{params: data});
}
//申请换货
export const applyChangeGoods = (data) =>{
  return axios.post('/orderBarter/exchangeGoods',data);
}
//换货申请列表
export const changeGoodsList = (data) =>{
  return axios.get('/orderBarter/exchangeList',data);
}
//登出
export const logout = (data) =>{
  return axios.get('/buyerUser/logout',data);
}
// 获取用户资料
export const getUser = () =>{
  return axios.post('/buyerUser/getBuyerUser');
}
//修改用户资料
export const modifyUser = (data) =>{
  return axios.post('/buyerUser/buyerUserModify', data);
}
//提交采购申请
export const submitEstablishApply = (data) =>{
  return axios.post('/shoppingCart/submitEstablishApply',data);
}
//我的采购审批接口
export const myPruchaseExa = () =>{
  return axios.post('/shoppingCart/myPruchaseExa');
}
//审批采购单数据接口
export const exaPurchase = (data) =>{
  return axios.post('/shoppingCart/exaPurchase', data);
}
//获取采购申请列表
export const getPurchaseRequestList = () =>{
  return axios.get('/orderSub/myPurchaseRequest');
}
//获取采购列表
export const getPurchaseList = (data) =>{
  return axios.post('/shoppingCart/purchase', data);
}
//采购详情
export const getPurchaseDetail = (data) =>{
  return axios.post('/shoppingCart/purchaseDetails', data);
}
//获取首页图片
export const adImageList = (data) =>{
  return axios.post('/ware/adImageList', data);
}
//获取首页菜单
export const mainMenuList = (data) =>{
    return axios.post('/ware/mainMenuList', data);
}
//获取楼层数据
export const getFloorList = (data) =>{
  return axios.post('/ware/getFloorList', data);
}
//猜你喜欢
export const getGuessYouLikeList = (data) =>{
  return axios.post('/ware/getGuessYouLikeList', data);
}
//搜索页数据接口
export const getSearchData = () =>{
  return axios.post('/wareSearch/getSearchData');
}
//获取商品列表
export const getWareList = (data) =>{
  return axios.get('/ware/wareList', {params: data});
}
//商品收藏
export const favorites = (data) =>{
  return axios.post('/wareFavorites/favorites', data);
}
//获取商品详情
export const getWareDetail = (data) =>{
  return axios.post('/ware/wareDetails', data);
}
//加入采购单
export const addPurchaseOrder = (data) =>{
  return axios.post('/shoppingCart/addPurchaseOrder', data);
}
// 获取验证码
export const getCode = (data) =>{
  return axios.post('/buyer/getCode', data);
}
//分类
export const getCategory = (data) =>{
  return axios.post('/wareCategory/category', data);
}
// 品牌列表
export const getBrandList = (data) =>{
  return axios.get('/wareCategory/getBrandList', {params: data});
}
//热门
export const getHotTags = (data) =>{
  return axios.get('/wareTages/getHotTags');
}
//订单数量
export const getOrderNum = (data) =>{
  return axios.post('/orderSub/myOrderNumList', data);
}
//订单列表
export const  getOrderList = (data) =>{
  return axios.post('/orderSub/orderList', data);
}
//订单详情
export const  getOrderDetail = (data) =>{
  return axios.post('/orderSub/orderDetails', data);
}
//获取订单数据接口
export const  establishOrderInfo = (data) =>{
  return axios.post('/shoppingCart/establishOrderInfo', data);
}
//支付接口
export const  orderPay = (data) =>{
  return axios.post('/order/orderPay', data);
}
// 获取分类品牌信息
export const categoryAndBrand = (data) =>{
  return axios.get('/wareCategory/categoryAndBrand', {params: data});
}
//修改采购单
export const pruchaseModify = (data) =>{
  return axios.post('/shoppingCart/pruchaseModify', data);
}
// 采购审批
export const pruchaseModifyExa = (data) =>{
  return axios.post('/shoppingCart/pruchaseModifyExa', data);
}
//是否有采购单数据
export const pruchaseNum = (data) =>{
  return axios.post('/shoppingCart/pruchaseNum', data);
}
// 是否有子账号采购单数据接口
export const subPruchaseNum = (data) =>{
  return axios.post('/shoppingCart/subPruchaseNum', data);
}
//是否有审核中的子帐号采购单接口
export const inAuditPruchase = (data) =>{
  return axios.post('/shoppingCart/inAuditPruchase', data);
}
//生成订单
export const establishOrder = (data) =>{
  return axios.post('/shoppingCart/establishOrder', data);
}
//删除订单
export const deleteOrder = (data) =>{
  return axios.post('/order/setOrderNotShow', data);
}
// 根据购物车id删除采购单接口
export const delShoppingCartById = (data) =>{
  return axios.post('/shoppingCart/delShoppingCartById', data);
}
// 根据地址id删除采购单
export const deletePurchase = (data) =>{
  return axios.post('/shoppingCart/delPurchase', data);
}
// 爆品馆
export const hotGoods = (data) =>{
  return axios.post('/ware/getWareByTagsAndCat', data);
}
//新品馆
export const newGoods = (data) =>{
  return axios.post('/ware/getNewWare', data);
}
//确认收货
export const confirmReceipt = (data) =>{
  return axios.post('/orderSub/confirmReceipt', data);
}
//更新订单接口
export const orderModify = (data) =>{
  return axios.post('/orderSub/orderModify', data);
}
// 获取发票信息
export const getInvoice = (data) =>{
  return axios.post('/orderSub/getInvoice', data);
}
// 设置发票信息
export const setInvoice = (data) =>{
  return axios.post('/invoice/setInvoice', data);
}
//设置订单备注
export const setOrderDesc = (data) =>{
  return axios.post('/order/setOrderDesc', data);
}
//退款
export const orderApplyRefund = (data) =>{
  return axios.post('/order/orderApplyRefund', data);
}
//收藏商店
export const shopFavorites = (data) =>{
  return axios.post('/shopFavorites/shopFavorites', data);
}
//店铺收藏列表
export const myShopFavorites = (data) =>{
  return axios.post('/shopFavorites/myShopFavorites', data);
}
//供应商信息接口
export const supplierInfo = (data) =>{
  return axios.post('/supplier/supplierInfo', data);
}
//取消店铺收藏
export const cancelShopFavorites = (data) =>{
  return axios.post('/shopFavorites/cancelShopFavorites', data);
}
//采购订单
// export const myPurchaseOrder = (data) =>{
//   return axios.post('/orderSub/myPurchaseOrder', data);
// }
// //我的采购申请-采购申请-采购申请详情
// export const myPurchaseRequestDetails = (data) =>{
//   return axios.post('/orderSub/myPurchaseRequestDetails', data);
// }
//商品预售功能
export const purchasePromptPresale = (data) =>{
  return axios.post('/shoppingCart/purchasePromptPresale', data);
}
//采购单时间日志
export const shopLogTime = (data) =>{
  return axios.post('/orderLogTime/shopLogTime', data);
}
// 查询店铺收藏接口
export const getShopFavoritesStatus = (data) =>{
  return axios.post('/shopFavorites/getShopFavoritesStatus', data);
}
// 忘记密码获取验证码
export const forgotGetCode = (data) =>{
  return axios.post('/buyer/forgotGetCode', data);
}
//微信授权接口
export const weixinAttorney = (data) =>{
    return axios.post('/buyerUser/weixinAttorney?' + parseInt(Math.random()*1e10), data);
}
//清除历史搜索
export const clearHistory =(data) =>{
    return axios.post('/wareSearch/clearHistory', data);
}
//我购买过的商品
export const searchWareListTow =(data) =>{
    return axios.post('/ware/searchWareListTow', data);
}
//售后插入
export const insertBuyerAfterSales =(data) =>{
    return axios.post('/buyerUser/insertBuyerAfterSales', data);
}
//获取订单可用熊猫币
export const usablePandaCoins =(data) =>{
    return axios.post('/buyer/usablePandaCoins', data);
}
//获取熊猫币列表
export const pandaCoins =(data) =>{
    return axios.post('/buyer/pandaCoins', data);
}